#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Linq;
using EstateNuke.Data;

#endregion

namespace EstateNuke.BusinessSystem.Categories.Business.Controls
{
    public partial class CustomerCommunicationControl : EstateNukeControl
    {
        private Customer _currentCustomer;
        public CustomerCommunicationControl()
        {
            InitializeComponent();
        }

        public void Action(Customer _customer, CommunicationAction action)
        {
            _currentCustomer = _customer;
            switch (action)
            {
                    case CommunicationAction.Add:
                        CommunicationType.DataSource = DBContext.GetAllCommunicationTypes();
                        CommunicationType.DisplayMember = "Name";
                        CommunicationType.SelectedIndex = 0;

                        CommunicationDate.Value = DateTime.Now;
                        CommunicationTime.Value = DateTime.Now;
                        CommunicationComment.Text = string.Empty;
                    break;
                    case CommunicationAction.Save:
                        CustomerCommunication customerCommunication = _currentCustomer.AddCustomerCommunication(CurrentUser);
                        customerCommunication.CommunicationType = (CommunicationType)CommunicationType.SelectedItem;
                        customerCommunication.Comment = CommunicationComment.Text;
                        customerCommunication.CommunicationDate = DateTime.Parse(CommunicationDate.Value.ToShortDateString() + " " + CommunicationTime.Text);

                        if (IsAlert.Checked)
                            customerCommunication.CreateCustomerCommunicationScheduledCallbackAlert(DBContext.AlertTypeEnum.CustomerCommunicationScheduledCallback,CurrentUser);

                        DBContext.SaveChanges(_currentCustomer);
                        break;
                    case CommunicationAction.Cancel:
                        DBContext.CancelChanges(_currentCustomer);
                    break;
            }
        }
    }
}